// pages/home_page/home_page.js

Page({
    
    /**
     * 页面的初始数据
     */
    data: {
        searchValue:'',
        showing_courses:[],
        nb_course:[],
        
        //轮播图数据
        data_slides:[
            {
                id:0,
                image:"/static/team.png",
                tar_url:"/pages/comment/comment"
            },
        ],
        data_implementation:[
            {
                id:0,
                name:"搜索",
                image:"/static/search.png",
                tar_url:"/pages/index/index"
            },
            {
                id:1,
                name:"专业课",
                image:"/static/mulu.png",
                tar_url:"/pages/wandering_index/wandering_index"
            },
            {
                id:2,
                name:"公共课",
                image:"/static/mulu.png",
                tar_url:"/pages/wandering_index/public_course"
               
            },            
            {
                id:3,
                name:"通识课",
                image:"/static/mulu.png",
                tar_url:"/pages/wandering_index/common_course"
            }
        ],

        
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad() {
        var that = this
        wx.request({
          url: 'https://data.docta.asia:8000/nb_class/',
          method:'post',
          data:(
              {
                  nb_id:this.data.nb_id,
              }
          ),
          header: {         
            "Content-Type": "application/x-www-form-urlencoded;charset = utf-8 "
        },
        //成功返回值时    

        success:function(res){    
            console.log(res) 
            const course_copy=res.data.nb_course
            // 利用id值去得到课程信息
            const nb_course=course_copy.map(item => ({course_id : item}))
            that.setData({nb_course}) 
            console.log(that.data.nb_course)
        }    
        }) 
    },

    onChange(e) {
        const index = e.detail.index
        this.setData(this.data.showing_courses=this.data.nb_course[index])
      },

    TapSwiperImage(e){
        const index = e.detail.index
        this.setData(this.data.showing_courses=this.data.nb_course[index])
    },

    TapImplementation(event){
        var tar_url=this.data.data_implementation[event.target.dataset.id].tar_url
        console.log(tar_url)
        wx.navigateTo({
          url: tar_url,
        })
    },

   
    
  
})